var xmlhttp = false; 

    try {  
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");  
    } catch (e) {  
        try {  
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");  
        } catch (e2) {  
            xmlhttp = false;  
        }  
    }  
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {  
        xmlhttp = new XMLHttpRequest();  
    }  
    function AjaxUserName(data){      
        xmlhttp.open("GET",BASE_PATH + "/RegisterServlet?method=CheckUserName&username="+data,true);  
        xmlhttp.send(null);  
        document.getElementById('username_notice').innerHTML = process_request;//显示状态  
        xmlhttp.onreadystatechange=function(){  
            if (4==xmlhttp.readyState){  
                if (200==xmlhttp.status){  
                var responseText = xmlhttp.responseText;  
                   if (responseText=="true" ){  
                   ck_user("true");  
                      }  
                   else{  
                   ck_user("false");  
                   }  
                }else{  
                    alert("发生错误!");  
                }  
            }  
        }  
    }  
    function chkUserName(obj){  
         if (checks(obj.value)== false)  
          {  
	  //更改当前标签的class，不需要
            //obj.className = "FrameDivWarn";  
            showInfo("username_notice",msg_un_format);  
			//此处并不更改提交按钮的状态，不需要
           // change_submit("true");  
          }  
        else if(obj.value.length<1){  
            //obj.className = "FrameDivWarn";  
            showInfo("username_notice",msg_un_blank);  
            //change_submit("true");  
        }  
  
        else if(obj.value.length<3){  
            //obj.className = "FrameDivWarn";  
            showInfo("username_notice",username_shorter);  
            //change_submit("true");  
        }  
        else{  
            //调用Ajax函数,向服务器端发送查询  
            AjaxUserName(obj.value);  
        }             
  
    }
    
//---------------验证手机号--------------------//
    function chkPhoneNum(obj){
    	if (checks(obj.value)== false)  
        {  
	  //更改当前标签的class，不需要
          //obj.className = "FrameDivWarn";  
          showInfo("phonenum_notice",mobile_phone_un_format);  
			//此处并不更改提交按钮的状态，不需要
         // change_submit("true");  
        }  
      else if(checkphone(obj.value)== false){
          //obj.className = "FrameDivWarn";  
          showInfo("phonenum_notice",mobile_phone_invalid);  
          //change_submit("true");  
      }  
    	
      else{  
          //调用Ajax函数,向服务器端发送查询  
          AjaxPhoneNum(obj.value);  
      }             
    	
    }
    
    function checkphone(phonenum){
    	return /^0{0,1}13[0-9]{9}$/.test(phonenum);
    }
    
    function AjaxPhoneNum(data){      
        xmlhttp.open("GET",BASE_PATH + "/RegisterServlet?method=CheckPhoneNum&phonenum="+data,true);  
        xmlhttp.send(null);  
        document.getElementById('phonenum_notice').innerHTML = process_request;//显示状态  
        xmlhttp.onreadystatechange=function(){  
            if (4==xmlhttp.readyState){  
                if (200==xmlhttp.status){  
                var responseText = xmlhttp.responseText;  
                   if (responseText=="true" ){  
                	   ck_phonenum("true");  
                      }  
                   else{  
                	   ck_phonenum("false");  
                   }  
                }else{  
                    alert("发生错误!");  
                }  
            }  
        }  
    }
    
    function ck_phonenum(result)  
    {  
      if ( result == "true" )  
      {    
        //document.getElementById('username').className = "FrameDivWarn";  
        showInfo("phonenum_notice",msg_phone_un_registered);  
        //change_submit("true");//禁用提交按钮  
      }  
      else  
      {   
        //document.getElementById('username').className = "FrameDivPass";  
        showInfo("phonenum_notice",msg_phone_can_rg);  
        //change_submit("false");//可用提交按钮  
      }  
    }  
//--------------用户名检测---------------------//  
function ck_user(result)  
{  
  if ( result == "true" )  
  {    
    //document.getElementById('username').className = "FrameDivWarn";  
    showInfo("username_notice",msg_un_registered);  
    //change_submit("true");//禁用提交按钮  
  }  
  else  
  {   
    //document.getElementById('username').className = "FrameDivPass";  
    showInfo("username_notice",msg_can_rg);  
    //change_submit("false");//可用提交按钮  
  }  
}  
  
function checks(t){  
    szMsg="[#%&'\",;:=!^@]";  
     //alertStr="";  
    for(i=1;i<szMsg.length+1;i++){  
     if(t.indexOf(szMsg.substring(i-1,i))>-1){  
      //alertStr="请勿包含非法字符如[#_%&'",;:=!^]";  
      return false;  
     }  
    }  
    return true;  
   }  
//-----------EMAIL检测--------------------------------//  
function checkEmail(email)  
{  
	console.log("email:"+email);
 if (chekemail(email.value)==false)  
  
  {  
    //email.className = "FrameDivWarn";  
    showInfo("email_notice",msg_email_format);  
    //change_submit("true");    
 }   
   
else  
   {  
   showInfo("email_notice",info_right);  
   //email.className = "FrameDivPass";  
   //change_submit("false");   
   }  
}  
  
function chekemail(temail) {    
	return /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(temail);
// var pattern = "/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/";    
// if(pattern.match(temail)) {    
//  return true;    
// }    
// else {    
//  return false;    
// }    
}   

/*
===========================================
//是否是有效的身份证(中国)
===========================================
*/ 
function checkIDCard(idcard){
	var socialNo = idcard.value;
	if(checkIDCardNum(socialNo)){
		showInfo("idcard_notice",idcard_notice_r);
	}else{
		showInfo("idcard_notice",idcard_notice_w);
	}
}

function checkIDCardNum(socialNo)
{
	if (socialNo.length != 15 && socialNo.length != 18)  
    {  
      return (false);  
    }  
        
   var area={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"};   
       
     if(area[parseInt(socialNo.substr(0,2))]==null) {  
      
          return (false);  
     }   
    if (socialNo.length == 15)  
    {  
       pattern= /^\d{15}$/;  
       if (pattern.exec(socialNo)==null){  
            
          return (false);  
      }  
      var birth = parseInt("19" + socialNo.substr(6,2));  
      var month = socialNo.substr(8,2);  
      var day = parseInt(socialNo.substr(10,2));  
      switch(month) {  
          case '01':  
          case '03':  
          case '05':  
          case '07':  
          case '08':  
          case '10':  
          case '12':  
              if(day>31) {  
                  
                  return false;  
              }  
              break;  
          case '04':  
          case '06':  
          case '09':  
          case '11':  
              if(day>30) {  
                  
                  return false;  
              }  
              break;  
          case '02':  
              if((birth % 4 == 0 && birth % 100 != 0) || birth % 400 == 0) {  
                  if(day>29) {  
                        
                      return false;  
                  }  
              } else {  
                  if(day>28) {  
                       
                      return false;  
                  }  
              }  
              break;  
          default:  
              return false;  
      }  
      var nowYear = new Date().getYear();  
      if(nowYear - parseInt(birth)<15 || nowYear - parseInt(birth)>100) {  
          return false;  
      }  
     
      return (true);  
    }  
      
    var Wi = new Array(  
              7,9,10,5,8,4,2,1,6,  
              3,7,9,10,5,8,4,2,1  
              );  
    var   lSum        = 0;  
    var   nNum        = 0;  
    var   nCheckSum   = 0;  
      
      for (i = 0; i < 17; ++i)  
      {  
          if ( socialNo.charAt(i) < '0' || socialNo.charAt(i) > '9' )  
          {  
              return (false);  
          }  
          else  
          {  
              nNum = socialNo.charAt(i) - '0';  
          }  
           lSum += nNum * Wi[i];  
      }  
      if( socialNo.charAt(17) == 'X' || socialNo.charAt(17) == 'x')  
      {  
          lSum += 10*Wi[17];  
      }  
      else if ( socialNo.charAt(17) < '0' || socialNo.charAt(17) > '9' )  
      {  
          return (false);  
      }  
      else  
      {  
          lSum += ( socialNo.charAt(17) - '0' ) * Wi[17];  
      }  
      if ( (lSum % 11) == 1 )  
      {  
          return true; 
      }  
      else  
      {  
          return (false);  
      }  
}


//--------------------密码检测-----------------------------//  
function check_password( password )  
{  
    if ( password.value.length < 6 )  
    {  
        showInfo("password_notice",password_shorter_s);  
        //password.className = "FrameDivWarn";  
        //change_submit("true");//禁用提交按钮  
    }  
    else if(password.value.length > 30){  
        showInfo("password_notice",password_shorter_m);  
        //password.className = "FrameDivWarn";  
        //change_submit("true");//禁用提交按钮  
        }  
    else  
    {  
        showInfo("password_notice",info_right);  
        //password.className = "FrameDivPass";  
        //change_submit("false");//允许提交按钮  
    }  
}  
  
function check_conform_password( conform_password )  
{  
    password = document.getElementById('password').value;  
      
    if ( conform_password.value.length < 6 )  
    {  
        showInfo("conform_password_notice",password_shorter_s);  
        //conform_password.className = "FrameDivWarn";  
        //change_submit("true");//禁用提交按  
        return false;  
    }  
    if ( conform_password.value!= password)  
    {  
        showInfo("conform_password_notice",confirm_password_invalid);  
        //conform_password.className = "FrameDivWarn";  
        //change_submit("true");//禁用提交按  
    }  
    else  
    {     
        //conform_password.className = "FrameDivPass";  
        showInfo("conform_password_notice",info_right);  
        //change_submit("false");//允许提交按钮  
    }  
}  
//* *--------------------检测密码强度-----------------------------* *//  
  
function checkIntensity(pwd)  
{  
  var Mcolor = "#FFF",Lcolor = "#FFF",Hcolor = "#FFF";  
  var m=0;  
  
  var Modes = 0;  
  for (i=0; i<pwd.length; i++)  
  {  
    var charType = 0;  
    var t = pwd.charCodeAt(i);  
    if (t>=48 && t <=57)  
    {  
      charType = 1;  
    }  
    else if (t>=65 && t <=90)  
    {  
      charType = 2;  
    }  
    else if (t>=97 && t <=122)  
      charType = 4;  
    else  
      charType = 4;  
    Modes |= charType;  
  }  
  
  for (i=0;i<4;i++)  
  {  
    if (Modes & 1) m++;  
      Modes>>>=1;  
  }  
  
  if (pwd.length<=4)  
  {  
    m = 1;  
  }  
  
  switch(m)  
  {  
    case 1 :  
      Lcolor = "2px solid red";  
      Mcolor = Hcolor = "2px solid #DADADA";  
    break;  
    case 2 :  
      Mcolor = "2px solid #f90";  
      Lcolor = Hcolor = "2px solid #DADADA";  
    break;  
    case 3 :  
      Hcolor = "2px solid #3c0";  
      Lcolor = Mcolor = "2px solid #DADADA";  
    break;  
    case 4 :  
      Hcolor = "2px solid #3c0";  
      Lcolor = Mcolor = "2px solid #DADADA";  
    break;  
    default :  
      Hcolor = Mcolor = Lcolor = "";  
    break;  
  }  
  document.getElementById("pwd_lower").style.borderBottom  = Lcolor;  
  document.getElementById("pwd_middle").style.borderBottom = Mcolor;  
  document.getElementById("pwd_high").style.borderBottom   = Hcolor;  
  
}  
//--------------注册协议复选框状态检测---------------------//  
function check_agreement(){  
  if (document.getElementById("agreement").checked==false)  
  {  
     showInfo("agreement_notice",agreement);  
     change_submit("true");//允许提交  
}  
  else  
  {  
    showInfo("agreement_notice",info_right);  
    change_submit("false");//允许提交按  
    }  
}  
  
  
//-------------处理注册程序-----------------------------//  
function register() {  
if(document.formUser.username.value=="")  
    {  
    showclass("username","FrameDivWarn");  
    showInfo("username_notice",msg_un_blank);  
      document.formUser.username.focus();  
      return false;  
     }  
 else if(document.formUser.email.value=="")  
    {  
      showclass("email","FrameDivWarn");  
      showInfo("email_notice",msg_email_blank);  
      document.formUser.email.focus();  
      return false;  
     }    
  
 else if(document.formUser.password.value=="")  
    {  
    showclass("password","FrameDivWarn");  
    showInfo("password_notice",password_empty);  
      document.formUser.password.focus();  
      return false;  
     }  
 else if(document.formUser.confirm_password.value=="")  
    {  
    showclass("confirm_password","FrameDivWarn");  
    showInfo("conform_password_notice",confirm_password_invalid);  
      document.formUser.password.focus();  
      return false;  
     }  
 else if(document.formUser.agreement.checked==false)  
    {  
    //showclass("agreement","FrameDivWarn");  
    showInfo("agreement_notice",agreement);  
      document.formUser.agreement.focus();  
      return false;  
     }  
}  



  
//------------ 按钮状态设置-----------------------------//  
function change_submit(zt)  
{   
     if (zt == "true")  
     {  
   document.forms['formUser'].elements['Submit1'].disabled = 'disabled';  
     }  
   else  
     {  
   document.forms['formUser'].elements['Submit1'].disabled = '';  
     }  
}  
//------公用程序------------------------------------//  
    function showInfo(target,Infos){  
    document.getElementById(target).innerHTML = Infos;  
	console.log(Infos);
    }  
    function showclass(target,Infos){  
    document.getElementById(target).className = Infos;  
	console.log(Infos);
    }     
var process_request = "正在数据处理中...";  
var username_empty = "<span style='COLOR:#ff0000'>  × 用户名不能为空!</span>";  
var username_shorter = "<span style='COLOR:#ff0000'> × 用户名长度不能少于 3 个字符。</span>";  
var username_invalid = "- 用户名只能是由字母数字以及下划线组成。";  
var password_empty = "<span style='COLOR:#ff0000'> × 登录密码不能为空。</span>";  
var password_shorter_s = "<span style='COLOR:#ff0000'> × 登录密码不能少于 6 个字符。</span>";  
var password_shorter_m = "<span style='COLOR:#ff0000'> × 登录密码不能多于 30 个字符。</span>";  
var confirm_password_invalid = "<span style='COLOR:#ff0000'> × 两次输入密码不一致!</span>";  
var email_empty = "<span style='COLOR:#ff0000'> × Email 为空</span>";  
var email_invalid = "- Email 不是合法的地址";  
var agreement = "<span style='COLOR:#ff0000'> × 您没有接受协议</span>";  
var mobile_phone_invalid = "<span style='COLOR:#ff0000'> × 手机号码不是一个有效号码";  
var msg_un_blank = "<span style='COLOR:#ff0000'> × 用户名不能为空!</span>";  
var msg_un_length = "<span style='COLOR:#ff0000'> × 用户名最长不得超过15个字符</span>";  
var msg_un_format = "<span style='COLOR:#ff0000'> × 用户名含有非法字符!</span>";  
var msg_un_registered = "<span style='COLOR:#ff0000'> × 用户名已经存在,请重新输入!</span>";  
var msg_can_rg = "<span style='COLOR:#006600'> √ 可以注册！</span>";  
var msg_email_blank = "<span style='COLOR:#ff0000'> × 邮件地址不能为空!</span>";  
var msg_email_registered = " × 邮箱已存在,请重新输入!";  
var msg_email_format = "<span style='COLOR:#ff0000'> × 邮件地址不合法!</span>";  
var username_exist = "用户名 %s 已经存在";  
var info_can="<span style='COLOR:#006600'> √ 可以注册!</span>";  
var info_right="<span style='COLOR:#006600'> √ 填写正确!</span>";  
var idcard_notice_w="<span style='COLOR:#ff0000'> × 身份证号不合法!</span>"; 
var idcard_notice_r="<span style='COLOR:#006600'> √ 身份证号正确!</span>"; 
var mobile_phone_un_format = "<span style='COLOR:#ff0000'> × 手机号含有非法字符!</span>";
var msg_phone_un_registered = "<span style='COLOR:#ff0000'> × 该手机号已经注册</span>"; 
var msg_phone_can_rg = "<span style='COLOR:#006600'> √ 该手机号可以注册</span>"; 


